package com.mcxx.modules.miniSalvation.special.service.read;

import com.mcxx.modules.base.entity.AreaGroupEntity;
import com.mcxx.modules.base.utils.QueryParamUtil;
import com.mcxx.modules.miniSalvation.family.dto.SalvationObjectDTO;
import com.mcxx.modules.miniSalvation.order.param.CaregiverParam;
import com.mcxx.modules.miniSalvation.special.dao.read.SpecialSignReadDao;
import com.mcxx.modules.miniSalvation.special.dto.SpecialSignDTO;
import com.mcxx.modules.miniSalvation.special.entity.SpecialSignEntity;
import com.mcxx.modules.miniSalvation.special.param.SpecialSignParam;
import com.mcxx.util.Constant;
import com.mcxx.util.DateUtil;
import com.yinhai.ta404.core.restservice.requestbean.PageParam;
import com.yinhai.ta404.core.restservice.resultbean.Page;
import com.yinhai.ta404.core.security.vo.UserAccountVo;
import com.yinhai.ta404.core.service.BaseService;
import com.yinhai.ta404.core.transaction.annotation.TaTransactional;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

@Service
@TaTransactional
public class SpecialSignReadService extends BaseService {
    @Autowired
    private SpecialSignReadDao specialSignReadDao;


    public Page querySpecialList(SpecialSignParam param, PageParam pageParam) {
        specialSignReadDao.beginPager(pageParam);
        List<SpecialSignDTO> list = specialSignReadDao.querySuspendList(param);
        return specialSignReadDao.endPager(list);
    }


    public int checkName(String name){return specialSignReadDao.checkName(name);}


    public int queryMaxSpecialValue(){return specialSignReadDao.queryMaxSpecialValue();}


    public Page getSalvationObjectList(SpecialSignParam param, PageParam pageParam, UserAccountVo accountVo) {

        QueryParamUtil.setBaseParamValue(param,accountVo);

        param.setSendMonth(DateUtil.getMonthString());

        specialSignReadDao.beginPager(pageParam);
        List<SalvationObjectDTO> list = specialSignReadDao.getSalvationObjectList(param);


        return specialSignReadDao.endPager(list);
    }


    public List<SpecialSignEntity> getSpecialSign(UserAccountVo accountVo) {

        List<SpecialSignEntity> SpecialSignList = specialSignReadDao.getSpecialSign();
        return SpecialSignList;
    }

    public Page getMemberSpecialSignList(SpecialSignParam param, PageParam pageParam, UserAccountVo accountVo) {

        QueryParamUtil.setBaseParamValue(param,accountVo);

        param.setSendMonth(DateUtil.getMonthString());
        if(!StringUtils.isEmpty(param.getSpecialValues())){
            String[] special = param.getSpecialValues().split(",");
            List<String> specialList = new ArrayList<>();
            for(String value : special){
                specialList.add(value);
            }
            param.setSpecialList(specialList);
        }


        specialSignReadDao.beginPager(pageParam);
        List<SalvationObjectDTO> list = specialSignReadDao.getMemberSpecialSignList(param);


        return specialSignReadDao.endPager(list);
    }


    public String getSpecialSignByIdcard(String idcard){return specialSignReadDao.getSpecialSignByIdcard(idcard);}

}
